using B.S.XZYData.Api.Read.Dto.Plan;
using System;
using System.Collections.Generic;

namespace B.S.XZYData.Api.Read.Dto.WorkOrder
{
    /// <summary>
    /// 工单综合信息DTO（包含产品、工单、工序、分派等完整信息）
    /// </summary>
    public class WorkOrderComprehensiveInfoDto
    {
        /// <summary>
        /// 工单基本信息
        /// </summary>
        public WorkOrderDetailDto WorkOrder { get; set; } = new WorkOrderDetailDto();

        /// <summary>
        /// 关联的计划明细信息（包含更详细的产品信息）
        /// </summary>
        public PlanItemDto? PlanItem { get; set; }

        /// <summary>
        /// 产品完整信息
        /// </summary>
        public ProductInfoDto ProductInfo { get; set; } = new ProductInfoDto();

        /// <summary>
        /// 工序进度统计
        /// </summary>
        public ProcessProgressSummaryDto ProcessProgress { get; set; } = new ProcessProgressSummaryDto();

        /// <summary>
        /// 分派统计信息
        /// </summary>
        public AssignSummaryDto AssignSummary { get; set; } = new AssignSummaryDto();
    }

    /// <summary>
    /// 产品完整信息DTO
    /// </summary>
    public class ProductInfoDto
    {
        /// <summary>
        /// 产品编号
        /// </summary>
        public string? ProductCode { get; set; }

        /// <summary>
        /// 产品名称
        /// </summary>
        public string? ProductName { get; set; }

        /// <summary>
        /// 规格
        /// </summary>
        public string? Spec { get; set; }

        /// <summary>
        /// 单位
        /// </summary>
        public string? Unit { get; set; }

        /// <summary>
        /// 计划数量（来自计划明细）
        /// </summary>
        public int? PlannedQuantityFromPlan { get; set; }

        /// <summary>
        /// 工单计划数量
        /// </summary>
        public int? PlannedQuantityFromWorkOrder { get; set; }

        /// <summary>
        /// 实际完成数量
        /// </summary>
        public int? ActualQuantity { get; set; }

        /// <summary>
        /// 良品数量
        /// </summary>
        public int? GoodQuantity { get; set; }

        /// <summary>
        /// 不良品数量
        /// </summary>
        public int? BadQuantity { get; set; }

        /// <summary>
        /// 完成进度百分比
        /// </summary>
        public decimal? CompletionPercentage { get; set; }
    }

    /// <summary>
    /// 工序进度统计DTO
    /// </summary>
    public class ProcessProgressSummaryDto
    {
        /// <summary>
        /// 总工序数
        /// </summary>
        public int TotalProcesses { get; set; }

        /// <summary>
        /// 已完成工序数
        /// </summary>
        public int CompletedProcesses { get; set; }

        /// <summary>
        /// 进行中工序数
        /// </summary>
        public int InProgressProcesses { get; set; }

        /// <summary>
        /// 未开始工序数
        /// </summary>
        public int PendingProcesses { get; set; }

        /// <summary>
        /// 工序进度百分比
        /// </summary>
        public decimal ProgressPercentage { get; set; }

        /// <summary>
        /// 当前工序信息
        /// </summary>
        public CurrentProcessDto? CurrentProcess { get; set; }
    }

    /// <summary>
    /// 当前工序DTO
    /// </summary>
    public class CurrentProcessDto
    {
        /// <summary>
        /// 工序ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 工序编号
        /// </summary>
        public string ProcessCode { get; set; } = string.Empty;

        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; } = string.Empty;

        /// <summary>
        /// 状态
        /// </summary>
        public string? Status { get; set; }

        /// <summary>
        /// 计划数量
        /// </summary>
        public int? PlannedQuantity { get; set; }

        /// <summary>
        /// 已报工数
        /// </summary>
        public int? ReportedQuantity { get; set; }
    }

    /// <summary>
    /// 分派统计DTO
    /// </summary>
    public class AssignSummaryDto
    {
        /// <summary>
        /// 总分派数量
        /// </summary>
        public int TotalAssignQuantity { get; set; }

        /// <summary>
        /// 分派员工数
        /// </summary>
        public int AssignedEmployeeCount { get; set; }

        /// <summary>
        /// 分派详情列表（按工序分组）
        /// </summary>
        public List<ProcessAssignSummaryDto> ProcessAssigns { get; set; } = new List<ProcessAssignSummaryDto>();
    }

    /// <summary>
    /// 工序分派统计DTO
    /// </summary>
    public class ProcessAssignSummaryDto
    {
        /// <summary>
        /// 工序ID
        /// </summary>
        public int ProcessId { get; set; }

        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; } = string.Empty;

        /// <summary>
        /// 工序分派数量
        /// </summary>
        public int AssignQuantity { get; set; }

        /// <summary>
        /// 分派员工数
        /// </summary>
        public int EmployeeCount { get; set; }

        /// <summary>
        /// 员工分派列表
        /// </summary>
        public List<EmployeeAssignDto> EmployeeAssigns { get; set; } = new List<EmployeeAssignDto>();
    }

    /// <summary>
    /// 员工分派DTO
    /// </summary>
    public class EmployeeAssignDto
    {
        /// <summary>
        /// 员工ID
        /// </summary>
        public int EmployeeId { get; set; }

        /// <summary>
        /// 员工姓名
        /// </summary>
        public string EmployeeName { get; set; } = string.Empty;

        /// <summary>
        /// 分派数量
        /// </summary>
        public int Quantity { get; set; }
    }
}
